package com.csoa.community.db;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;

import com.csoa.community.bean.DataStatisticsBean;
import com.csoa.community.bean.WZInfoBean;
import com.csoa.community.bean.YFInfoBean;

public class WZInfoDB extends DataBaseDB {

	/**
	 * 样方信息插入操作
	 * 
	 * @param lm
	 */
	// 总共31项
	public static void insert(WZInfoBean wzInfo) {
		DataBaseDB.getInst().getDB();
		String sql = "insert into WZInfoTable(" + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				") values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		db.beginTransaction();
		try {
			db.execSQL(
					sql,
					new String[] { String.valueOf(wzInfo.yfId), wzInfo.groupId,
							wzInfo.surveyMethod, wzInfo.chineseName,
							wzInfo.latinName, wzInfo.commonName,
							wzInfo.characters, wzInfo.quantity,
							wzInfo.coverage, wzInfo.height,
							wzInfo.frequentness, wzInfo.DBH, wzInfo.phenology,
							String.valueOf(wzInfo.phenologyPosition),
							wzInfo.viability,
							String.valueOf(wzInfo.viabilityPosition),
							wzInfo.niche, String.valueOf(wzInfo.nichePosition),
							wzInfo.threatFactors, wzInfo.specimenNumber,
							wzInfo.photoNumber, wzInfo.smallQuadratNumber,
							wzInfo.importantLevel, wzInfo.level,
							String.valueOf(wzInfo.levelPosition),
							wzInfo.formations, wzInfo.distributionType,
							String.valueOf(wzInfo.distributionTypePosition),
							wzInfo.imgPath, 
							wzInfo.imgTitle,
							wzInfo.imgAuthor,
							wzInfo.videoPath,
							wzInfo.videoTitle,
							wzInfo.videoAuthor,
							wzInfo.distributionArea });
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
	}

	/**
	 * 查询某个样方信息
	 * 
	 * @param lm
	 */
	public static WZInfoBean queryById(String id) {
		DataBaseDB.getInst().getDB();
		String sql = "select " + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				" from WZInfoTable where id=?";
		db.beginTransaction();
		Cursor cursor = null;
		WZInfoBean wzInfo = null;
		try {
			cursor = db.rawQuery(sql, new String[] { id });
			if (cursor.getCount() > 0) {
				cursor.moveToNext();
				wzInfo = parseWZInfo(cursor);
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return wzInfo;
	}
	
	
	
	/**
	 * 查询所有样方信息
	 * 
	 * @param lm
	 */
	public static List<DataStatisticsBean> queryStatistics(List<YFInfoBean> yfInfos,String chineseName) {
		if(yfInfos == null || yfInfos.size() == 0) {
			return null;
		}
		DataBaseDB.getInst().getDB();
		String sql = "select id," + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				" from WZInfoTable where chineseName like ? and yfId=?";
		db.beginTransaction();
		Cursor cursor = null;
		List<DataStatisticsBean> datas = null;
		
		
		
		try {
			datas = new ArrayList<DataStatisticsBean>();
			for(int i=0;i<yfInfos.size();i++) {
				YFInfoBean yfinfo = yfInfos.get(i);
				cursor = db.rawQuery(sql, new String[]{"%" + chineseName + "%",String.valueOf(yfinfo.id)});
				if (cursor.getCount() > 0) {
					while (cursor.moveToNext()) {
						DataStatisticsBean data = parseDataStatistic(yfinfo,cursor);
						datas.add(data);
					}

				}
				if (cursor != null) {
					cursor.close();
					cursor = null;

				}
			}
			
			

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return datas;
	}
	
	
	/**
	 * 查询所有样方信息
	 * 
	 * @param lm
	 */
	public static List<DataStatisticsBean> queryStatistics(List<YFInfoBean> yfInfos) {
		if(yfInfos == null || yfInfos.size() == 0) {
			return null;
		}
		DataBaseDB.getInst().getDB();
		String sql = "select id," + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				" from WZInfoTable where yfId=?";
		db.beginTransaction();
		Cursor cursor = null;
		List<DataStatisticsBean> datas = null;
		
		
		
		try {
			datas = new ArrayList<DataStatisticsBean>();
			for(int i=0;i<yfInfos.size();i++) {
				YFInfoBean yfinfo = yfInfos.get(i);
				cursor = db.rawQuery(sql, new String[]{String.valueOf(yfinfo.id)});
				int count = cursor.getCount();
				if (count > 0) {
					while (cursor.moveToNext()) {
						DataStatisticsBean data = parseDataStatistic(yfinfo,cursor);
						datas.add(data);
					}

				}
				if (cursor != null) {
					cursor.close();
					cursor = null;

				}
			}
			
			

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return datas;
	}

	/**
	 * 解析物种对象
	 * 
	 * @param wzInfo
	 * @param cursor
	 */
	private static DataStatisticsBean parseDataStatistic(YFInfoBean yfinfo,Cursor cursor) {
		DataStatisticsBean data = new DataStatisticsBean();
		data.id = cursor.getInt(cursor.getColumnIndex("id"));
		data.groupId = cursor.getString(cursor.getColumnIndex("grounpId"));
		data.gridNumber = yfinfo.gridNumber;
		data.quadratsNumber = yfinfo.quadratsNumber;
		data.surveyMethod = yfinfo.surveyMethod;
		data.surveyArea = yfinfo.area;
		data.chineseName = cursor.getString(cursor.getColumnIndex("chineseName"));
		data.latinName = cursor.getString(cursor.getColumnIndex("latinName"));
		data.type = "植物";
		return data;
	}

	/**
	 * 解析物种对象
	 * 
	 * @param wzInfo
	 * @param cursor
	 */
	private static WZInfoBean parseWZInfo(Cursor cursor) {
		WZInfoBean wzInfo = new WZInfoBean();
		wzInfo.id = cursor.getInt(cursor.getColumnIndex("id"));
		wzInfo.yfId = cursor.getInt(cursor.getColumnIndex("yfId"));
		wzInfo.groupId = cursor.getString(cursor.getColumnIndex("grounpId"));
		wzInfo.surveyMethod = cursor.getString(cursor
				.getColumnIndex("surveyMethod"));
		wzInfo.chineseName = cursor.getString(cursor
				.getColumnIndex("chineseName"));
		wzInfo.latinName = cursor.getString(cursor.getColumnIndex("latinName"));
		wzInfo.commonName = cursor.getString(cursor
				.getColumnIndex("commonName"));
		wzInfo.characters = cursor.getString(cursor
				.getColumnIndex("characters"));
		wzInfo.quantity = cursor.getString(cursor.getColumnIndex("quantity"));
		wzInfo.coverage = cursor.getString(cursor.getColumnIndex("coverage"));
		wzInfo.height = cursor.getString(cursor.getColumnIndex("height"));
		wzInfo.frequentness = cursor.getString(cursor
				.getColumnIndex("frequentness"));
		wzInfo.DBH = cursor.getString(cursor.getColumnIndex("DBH"));
		wzInfo.phenology = cursor.getString(cursor.getColumnIndex("phenology"));
		wzInfo.phenologyPosition = cursor.getInt(cursor
				.getColumnIndex("phenologyPosition"));
		wzInfo.viability = cursor.getString(cursor.getColumnIndex("viability"));
		wzInfo.viabilityPosition = cursor.getInt(cursor
				.getColumnIndex("viabilityPosition"));
		wzInfo.niche = cursor.getString(cursor.getColumnIndex("niche"));
		wzInfo.nichePosition = cursor.getInt(cursor
				.getColumnIndex("nichePosition"));
		wzInfo.threatFactors = cursor.getString(cursor
				.getColumnIndex("threatFactors"));
		wzInfo.specimenNumber = cursor.getString(cursor
				.getColumnIndex("specimenNumber"));
		wzInfo.photoNumber = cursor.getString(cursor
				.getColumnIndex("photoNumber"));
		wzInfo.smallQuadratNumber = cursor.getString(cursor
				.getColumnIndex("smallQuadratNumber"));
		wzInfo.importantLevel = cursor.getString(cursor
				.getColumnIndex("importantLevel"));
		wzInfo.level = cursor.getString(cursor.getColumnIndex("level"));
		wzInfo.levelPosition = cursor.getInt(cursor
				.getColumnIndex("levelPosition"));
		wzInfo.formations = cursor.getString(cursor
				.getColumnIndex("formations"));
		wzInfo.distributionType = cursor.getString(cursor
				.getColumnIndex("distributionType"));
		wzInfo.distributionTypePosition = cursor.getInt(cursor
				.getColumnIndex("distributionTypePosition"));
		wzInfo.imgPath = cursor.getString(cursor.getColumnIndex("imgPath"));
		wzInfo.imgTitle = cursor.getString(cursor.getColumnIndex("imgTitle"));
		wzInfo.imgAuthor = cursor.getString(cursor.getColumnIndex("imgAuthor"));
		wzInfo.videoPath = cursor.getString(cursor.getColumnIndex("videoPath"));
		wzInfo.videoTitle = cursor.getString(cursor.getColumnIndex("videoTitle"));
		wzInfo.videoAuthor = cursor.getString(cursor.getColumnIndex("videoAuthor"));
		wzInfo.distributionArea = cursor.getString(cursor
				.getColumnIndex("distributionArea"));
		
		return wzInfo;
	}

	/**
	 * 查询所有样方信息
	 * 
	 * @param lm
	 */
	public static List<WZInfoBean> query() {
		DataBaseDB.getInst().getDB();
		String sql = "select " + "id," + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				" from WZInfoTable order by id desc";
		db.beginTransaction();
		Cursor cursor = null;
		List<WZInfoBean> wzInfos = null;
		try {
			cursor = db.rawQuery(sql, null);
			if (cursor.getCount() > 0) {
				wzInfos = new ArrayList<WZInfoBean>();
				while (cursor.moveToNext()) {
					WZInfoBean wzInfo = parseWZInfo(cursor);
					wzInfos.add(wzInfo);
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return wzInfos;
	}

	/**
	 * 查询所有样方信息
	 * 
	 * @param lm
	 */
	public static List<WZInfoBean> query(int yfid) {
		DataBaseDB.getInst().getDB();
		String sql = "select " + "id," + "yfId," + "grounpId ," + // 课题组id
				"surveyMethod  ," + // 所属调查方法
				"chineseName  ," + // 中文名
				"latinName  ," + // 拉丁名称
				"commonName  ," + // 俗名
				"characters  ," + // 性状
				"quantity  ," + // 数量
				"coverage  ," + // 盖度
				"height  ," + // 高度
				"frequentness  ," + // 高度
				"DBH  ," + // 胸径
				"phenology  ," + // 物候
				"phenologyPosition  ," + // 物候
				"viability  ," + // 生活力
				"viabilityPosition  ," + // 生活力
				"niche  ," + // 生态位
				"nichePosition  ," + // 生态位
				"threatFactors  ," + // 受威胁因素
				"specimenNumber  ," + // 标本号
				"photoNumber ," + // 照片号
				"smallQuadratNumber ," + // 小样方号
				"importantLevel ," + // 重要级别
				"level ," + // 层次
				"levelPosition ," + // 层次
				"formations ," + // 群系
				"distributionType ," + // 分布类型
				"distributionTypePosition ," + // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath," + 
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea " + // 分布区域
				" from WZInfoTable where yfId=? order by id desc";
		db.beginTransaction();
		Cursor cursor = null;
		List<WZInfoBean> wzInfos = null;
		try {
			cursor = db.rawQuery(sql, new String[] { String.valueOf(yfid) });
			if (cursor.getCount() > 0) {
				wzInfos = new ArrayList<WZInfoBean>();
				while (cursor.moveToNext()) {
					WZInfoBean wzInfo = parseWZInfo(cursor);
					wzInfos.add(wzInfo);
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return wzInfos;
	}

	/**
	 * 
	 * @param yfId
	 * @return
	 */
	public static int getWZCount(int yfId) {
		DataBaseDB.getInst().getDB();
		String sql = "select count(*) from WZInfoTable where yfId=" + yfId;
		db.beginTransaction();
		Cursor cursor = null;
		int count = 0;
		try {
			cursor = db.rawQuery(sql, null);
			if (cursor.getCount() > 0) {
				cursor.moveToNext();
				count = cursor.getInt(0);
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return count;
	}

	/**
	 * 查询所有样方信息
	 * 
	 * @param lm
	 */
	public static List<WZInfoBean> query(String latinName, String chineseName,
			String commonName) {
		DataBaseDB.getInst().getDB();
		String sql = "select "
				+ "id,"
				+ "yfId,"
				+ "grounpId ,"
				+ // 课题组id
				"surveyMethod  ,"
				+ // 所属调查方法
				"chineseName  ,"
				+ // 中文名
				"latinName  ,"
				+ // 拉丁名称
				"commonName  ,"
				+ // 俗名
				"characters  ,"
				+ // 性状
				"quantity  ,"
				+ // 数量
				"coverage  ,"
				+ // 盖度
				"height  ,"
				+ // 高度
				"frequentness  ,"
				+ // 高度
				"DBH  ,"
				+ // 胸径
				"phenology  ,"
				+ // 物候
				"phenologyPosition  ,"
				+ // 物候
				"viability  ,"
				+ // 生活力
				"viabilityPosition  ,"
				+ // 生活力
				"niche  ,"
				+ // 生态位
				"nichePosition  ,"
				+ // 生态位
				"threatFactors  ,"
				+ // 受威胁因素
				"specimenNumber  ,"
				+ // 标本号
				"photoNumber ,"
				+ // 照片号
				"smallQuadratNumber ,"
				+ // 小样方号
				"importantLevel ,"
				+ // 重要级别
				"level ,"
				+ // 层次
				"levelPosition ,"
				+ // 层次
				"formations ,"
				+ // 群系
				"distributionType ,"
				+ // 分布类型
				"distributionTypePosition ,"
				+ // 分布类型
				"imgPath," + 
				"imgTitle,"+ 
				"imgAuthor,"+ 
				"videoPath,"+
				"videoTitle," + // luxiang
				"videoAuthor," + // zhaopian
				"distributionArea "
				+ // 分布区域
				" from WZInfoTable where " + "latinName like ? and "
				+ "chineseName like ? and " + "commonName like ?  "
				+ "order by id desc";
		db.beginTransaction();
		Cursor cursor = null;
		List<WZInfoBean> wzInfos = null;
		try {
			cursor = db.rawQuery(sql, new String[] { "%" + latinName + "%",
					"%" + chineseName + "%", "%" + commonName + "%" });
			if (cursor.getCount() > 0) {
				wzInfos = new ArrayList<WZInfoBean>();
				while (cursor.moveToNext()) {
					WZInfoBean wzInfo = parseWZInfo(cursor);
					wzInfos.add(wzInfo);
				}

			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (cursor != null) {
				cursor.close();
				cursor = null;

			}
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return wzInfos;
	}

	/**
	 * 删除某一个用户的登录信息
	 * 
	 * @param LoginBean
	 */
	public static void delete(WZInfoBean wzInfo) {
		DataBaseDB.getInst().getDB();
		String del = "delete from WZInfoTable where id=?";
		db.beginTransaction();
		try {
			db.execSQL(del, new String[] { String.valueOf(wzInfo.id) });
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}

	}

	public static void delete() {
		DataBaseDB.getInst().getDB();
		String del = "delete from WZInfoTable ";
		db.beginTransaction();
		try {
			db.execSQL(del, null);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}

	}

	/**
	 * 更新物种信息
	 * 
	 * @param lm
	 */
	public static boolean updateById(WZInfoBean wzInfo, int id) {
		DataBaseDB.getInst().getDB();
		String sql = "update WZInfoTable set " + "chineseName=?  ," + // 中文名
				"latinName=?  ," + // 拉丁名称
				"commonName=?  ," + // 俗名
				"characters=?  ," + // 性状
				"quantity=?  ," + // 数量
				"coverage=?  ," + // 盖度
				"height=?  ," + // 高度
				"frequentness=?  ," + // 高度
				"DBH=?  ," + // 胸径
				"phenology=?  ," + // 物候
				"phenologyPosition=?  ," + // 物候
				"viability=?  ," + // 生活力
				"viabilityPosition=?  ," + // 生活力
				"niche=?  ," + // 生态位
				"nichePosition=?  ," + // 生态位
				"threatFactors=?  ," + // 受威胁因素
				"specimenNumber=?  ," + // 标本号
				"photoNumber=? ," + // 照片号
				"smallQuadratNumber=? ," + // 小样方号
				"importantLevel=? ," + // 重要级别
				"level=? ," + // 层次
				"levelPosition=? ," + // 层次
				"formations=? ," + // 群系
				"distributionType=? ," + // 分布类型
				"distributionTypePosition=? ," + // 分布类型
				"imgPath=?," + 
				"imgTitle=?,"+ 
				"imgAuthor=?,"+ 
				"videoPath=?," +
				"videoTitle=?," + // luxiang
				"videoAuthor=?," + // zhaopian
				"distributionArea=? " + // 分布区域
				" where id=?";
		db.beginTransaction();
		try {
			db.execSQL(
					sql,
					new String[] { wzInfo.chineseName, wzInfo.latinName,
							wzInfo.commonName, wzInfo.characters,
							wzInfo.quantity, wzInfo.coverage, wzInfo.height,
							wzInfo.frequentness, wzInfo.DBH, wzInfo.phenology,
							String.valueOf(wzInfo.phenologyPosition),
							wzInfo.viability,
							String.valueOf(wzInfo.viabilityPosition),
							wzInfo.niche, String.valueOf(wzInfo.nichePosition),
							wzInfo.threatFactors, wzInfo.specimenNumber,
							wzInfo.photoNumber, wzInfo.smallQuadratNumber,
							wzInfo.importantLevel, wzInfo.level,
							String.valueOf(wzInfo.levelPosition),
							wzInfo.formations, wzInfo.distributionType,
							String.valueOf(wzInfo.distributionTypePosition),
							wzInfo.imgPath, 
							wzInfo.imgTitle,
							wzInfo.imgAuthor,
							wzInfo.videoPath,
							wzInfo.videoTitle,
							wzInfo.videoAuthor,
							wzInfo.distributionArea, String.valueOf(id) });
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		} finally {
			if (db.isOpen()) {
				db.setTransactionSuccessful();
				db.endTransaction();
				db.close();
			}
		}
		return true;
	}
}
